package warbots.entities.actions;


import java.awt.Point;

import warbots.entities.units.Unit;
import warbots.gameplay.Map;


/**
 * @author Ido Adler.
 */
public class MoveAction extends Action
{
    
    /**
     * TODO: description
     * 
     * @param parent
     * @param name
     * @param distance
     */
    public MoveAction(final Unit parent, final String name)
    {
        super(parent, name);
        _price = _parent.getSpeed();
    }
    
    /**
     * @see warbots.entities.actions.Action#execute(warbots.gameplay.Map,
     *      java.awt.Point)
     */
    @Override
    public boolean execute(final Map world, final Point target)
    {
        if (target.distance(_parent.getPosition()) <= _parent.getSpeed())
        {
            if (!world._board[target.x][target.y].isBlocked())
            {
                world._board[_parent.getPosition().x][_parent.getPosition().y].setUnit(null);
                world._board[target.x][target.x].setUnit(_parent);
                System.out.println(_parent.getName() + ":" + getName() + "->[" + target.x + ","
                    + target.y + "]");
                return true;
            }
        }
        return false;
    }
}
